﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AutumnEngine;
using System.IO;

namespace AutumnEngine.Editor
{
    public partial class AssetAddForm : Form
    {
        AssetType assetType;
        public AssetAddForm(AssetType type)
        {
            assetType = type;
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Done();
        }

        public void Done()
        {
            switch (assetType)
            {
                case AssetType.Texture:
                    {
                        Program.f.game.AddTexture(textBox1.Text, textBox2.Text);
                        break;
                    }
                case AssetType.Font:
                    {
                        Program.f.game.AddFont(textBox1.Text,textBox2.Text);
                        break;
                    }
                default:
                    {
                        throw new Exception("Received unknown AssetType");
                    }
            }
            Program.f.finishedAdding(assetType,textBox1.Text);
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            OpenFileDialog open = new OpenFileDialog();
            open.RestoreDirectory = true;
            open.AddExtension = true;
            open.AutoUpgradeEnabled = true;
            open.DefaultExt = "xnb";
            open.Filter = "Xna Content Files (*.xnb)|*.xnb";            
            
            open.Title = "Open Content...";
            open.InitialDirectory = Directory.GetCurrentDirectory() + "/Content";
            
            DialogResult res = open.ShowDialog();
            if (res == DialogResult.OK)
            {                
                string name = open.FileName;                
                name = name.Replace(Directory.GetCurrentDirectory() + "\\", "");
                if (name.EndsWith(".xnb"))
                {
                    name = name.Replace(".xnb", "");
                }
                this.textBox2.Text = name;
            }
            
        }

        private void AssetAddForm_Load(object sender, EventArgs e)
        {
            label3.Text = "Make sure that the path\nis inside the\nContent folder in the\nworking directory,\notherwise you will encounter\nfull paths in your scene file.";
        }
    }

    public enum AssetType
    {
        Texture,
        Font
    }
}
